package com.example.rxbyhand.scheduler;


import android.os.Handler;

/**
 * Author by lp,on 2021/8/17/017,11:46.
 */
public class HandlerScheduler extends Scheduler {
    final Handler handler;

    public HandlerScheduler(Handler handler) {
        this.handler = handler;
    }

    @Override
    public Worker creteWorker() {
        return new HandlerWorker(handler);
    }

    static final class HandlerWorker implements Worker {

        final Handler mapper;

        HandlerWorker(Handler mapper) {
            this.mapper = mapper;
        }

        @Override
        public void schedule(Runnable runnable) {
            mapper.post(runnable);

        }
    }
}
